#include <windows.h>

void ForceSetForegroundWindow(HWND hwnd)
{
	DWORD dwFGThreadId, dwFGProcessId;
	DWORD dwThisThreadId;

	HWND hwndForeground = GetForegroundWindow();
	
	dwFGThreadId = GetWindowThreadProcessId(hwndForeground, &dwFGProcessId);
	
	dwThisThreadId = GetCurrentThreadId();
	
	AttachThreadInput(dwThisThreadId, dwFGThreadId,TRUE);
	
	SetForegroundWindow(hwnd);
	BringWindowToTop(hwnd);
	SetFocus(hwnd);

	AttachThreadInput(dwThisThreadId, dwFGThreadId,FALSE);
}